package com.itheima.treesetdemo;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * Tree 集合存储Student类型
 */
public class TreeSetDemo4 {
    public static void main(String[] args) {
        TreeSet<Teacher> ts = new TreeSet<>((o1, o2) -> {
            int result = o1.getAge() - o2.getAge();
            result = (result == 0) ? o1.getName().compareTo(o2.getName()) : result;
            return result;
        });

        Teacher t1 = new Teacher("zhangsan", 23);
        Teacher t2 = new Teacher("lisi", 22);
        Teacher t3 = new Teacher("wangwu", 24);
        Teacher t4 = new Teacher("zhaoliu", 24);
        ts.add(t1);
        ts.add(t2);
        ts.add(t3);
        ts.add(t4);

        for (Teacher t : ts) {
            System.out.println(t);
        }
    }
}
